layui.use(["jquery", "upload", "form", "layer", "element", "laydate"], function () {
    var $ = layui.$,
        element = layui.element,
        layer = layui.layer,
        upload = layui.upload,
        form = layui.form;
        laydate  = layui.laydate;
    var user = JSON.parse(localStorage.getItem('user'));

    //设置日期
    laydate.render({
        elem: '#startDate'
        ,type: 'datetime'
    });

    laydate.render({
        elem: '#endDate'
        ,type: 'datetime'
    });



    form.on('submit(formDemo)', function(data){
        console.log(data);
        data.field.createId = user.userId;
        console.log(data.field);
        $.ajax({
            url:'/UserCoupon/addUserCoupon',
            type: 'post',
            dataType:'json',
            data:data.field,
            success:function (data) {
                if(data.data){
                    layer.msg("添加成功");
                    parent.$('#quickEntry').val('优惠券列表');
                    parent.quickEntry();
                }else{
                    layer.msg("添加失败");
                }
            }
        });
        return false;
    });

    function backOff() {
        var arr = localStorage.getItem("numArr");
        var numArr = arr.split(",");
        numArr.pop();
        window.parent.layui.element.tabChange('tab',numArr[numArr.length - 1]);
        localStorage.setItem("numArr",numArr);
    };
    //
    // //返回
    // backOff = function backOff() {
    //     location.href="couponList.html";
    // }

});